package cn.hxzy.service.impl;

import cn.hxzy.common.R;
import cn.hxzy.entity.Orders;
import cn.hxzy.entity.Train;
import cn.hxzy.entity.User;
import cn.hxzy.mapper.OrdersMapper;
import cn.hxzy.mapper.TrainMapper;
import cn.hxzy.mapper.UserMapper;
import cn.hxzy.service.OrdersService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuankan.WANG
 * @since 2022-01-13
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private TrainMapper trainMapper;

    @Override
    public R sel() {
        QueryWrapper wrapper=new QueryWrapper();
        List<Orders> list = ordersMapper.selectList(wrapper);
        for (Orders orders:list) {
            User user = userMapper.selectById(orders.getUserId());
            orders.setUserName(user.getUserName());
            Train train = trainMapper.selectById(orders.getTrainId());
            orders.setTrainName(train.getTrainName());
        }
        return R.ok().code(20000).message("查询成功").data("item",list);

//        QueryWrapper wrapper=new QueryWrapper();
//        wrapper.eq("ordersId",ordersId);
//        List list = ordersMapper.selectList(wrapper);
//        if (!Objects.isNull(list)){
//            return R.ok().code(20000).data("item",list).message("查询订单成功！");
//        }
//
//        return R.error().code(-20000).message("查询失败！");
    }
}
